package com.threadBase.demo04_synchronization;

import javax.swing.*;

/**
 * 同步测试
 */
public class
OurTest {
    public static void main(String[] args) {
        Thread02 thread02 = new Thread02();
        for (int i = 0; i < 2; i++) {
            new Thread(thread02,"线程"+i).start();
        }

    }
}

class Thread01 extends Thread{
    @Override
    public void run() {
        synchronized (Thread.class){
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
        }
    }
}

class Thread02 implements Runnable{

    @Override
    public void run() {
        int num =0;
        for (;num < 20; num++) {
            System.out.println(Thread.currentThread().getName()+"第"+num+"次！");

        }

    }
}
